
#include "comm.hpp"


int main()
{
    std::cout<<"test clinet"<<std::endl;
    //获取key值
    key_t key = GetKey();
    printf("key: 0x%x\n",key);

    //获取共享内存
    int shmid = GetShm(key);
    std::cout<<"shmid: "<<shmid<<std::endl;

    //挂接
    char* str = (char*)AttachShm(shmid);

    const char *arr = "我是clinet进程！！";
    int cnt =0;
    pid_t id = getpid();

    //进行通讯
    while(true)
    {
        snprintf(str, SHM_SIZE, "%s [pid:%d][消息编号：%d]", arr, id, cnt++);
        struct shmid_ds tmp;
        shmctl(shmid, IPC_STAT, &tmp );
        std::cout<<"创建此共享内存的进程id:"<<tmp.shm_cpid<<"key值："<<tmp.shm_perm.__key<<std::endl;
        sleep(5);
    }

    //去挂接
    DetachShm(str);
    return 0;
}